<?php
namespace Client\Table;

use Zend\Db\Sql\Select;
use Zend\Db\Sql\Where;

class MonitorReportTable extends CommonTable
{
	protected $table = 'hy_monitor_report';
	protected $id = 'monitor_report_id';
	
	
	public function getReports($materialId){
		if(empty($materialId)){
			throw new \Exception("材料Id出错!");
		}
    	$select = new Select($this->getTable());
    	$select->columns( array(
			'monitor_report_id','material_id','image','report_time','create_time','update_time'
    	));
    	$select->where(array('material_id' => $materialId));
    	$rowset= $this->selectWith($select);
    	$row = $rowset->toArray();
    	return $row;
	}
	
	public function searchMaterialReport($query){

		$select = new Select($this->getTable());
		$select->columns( array(
				'monitor_report_id','material_id','image','report_time','create_time','update_time'
		));
		
		if(!empty($query['material_id'])){
			$select->where(array('material_id' => $query['material_id']));
		}else{
			throw new \Exception("invalid material id");
		}
		if(!empty($query['y'])&&!empty($query['m'])&&!empty($query['d'])){
			$minTime=$query['y']."-".sprintf("%02u",$query['m'])."-".sprintf("%02u",$query['d']);
			$maxTime=date("Y-m-d",strtotime($minTime." +1 days"));
		}
		$select->where("report_time between '{$minTime}'  and '{$maxTime}'");
		//echo $select->getSqlString($this->adapter->getPlatform());
		$rowset= $this->selectWith($select);
		$row = $rowset->toArray();
		return $row;
	}
	
}